﻿function ClassDate(ImgPath)
{
	var	fixedX = -1			// x position (-1 if to appear below control)
	var	fixedY = -1			// y position (-1 if to appear below control)
	var startAt = 1			// 0 - sunday ; 1 - monday
	var showWeekNumber = 1	// 0 - don't show; 1 - show
	var showToday = 1		// 0 - don't show; 1 - show
	var imgDir = ImgPath			// directory for images ... e.g. var imgDir="/img/"

	var gotoString = "转到当前月份"
	var todayString = "今天是"
	var weekString = "周数"
	var scrollLeftMessage = "单击跳转到上一个月. 点住按钮月份将自动向前滚动."
	var scrollRightMessage = "单击跳转到下一个月. 点住按钮月份将自动向后滚动."
	var selectMonthMessage = "点击选择月份."
	var selectYearMessage = "点击选择年份."
	var selectDateMessage = "点击选择 [date] ." // do not replace [date], it will be replaced by date.

	var	crossobj, crossMonthObj, crossYearObj,   omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear

	this.dateSelected;
	this.monthSelected;
	this.yearSelected;

	this.intervalID1;
	this.intervalID2;
	this.timeoutID1;
	this.timeoutID2;
	
	var	bPageLoaded=false
	var	ie=document.all
	var	dom=document.getElementById

	var	ns4=document.layers
	var	today =	new	Date()
	var	dateNow	 = today.getDate()
	this.monthNow = today.getMonth()
	this.yearNow	 = today.getYear()
	var	imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
	var	img	= new Array()

	var bShow = false;

    /* hides <select> and <applet> objects (for IE only) */
    this.hideElement = function( elmID, overDiv )
    {
      if( ie )
      {
        for( i = 0; i < document.all.tags( elmID ).length; i++ )
        {
          obj = document.all.tags( elmID )[i];
          if( !obj || !obj.offsetParent )
          {
            continue;
          }
      
          // Find the element's offsetTop and offsetLeft relative to the BODY tag.
          objLeft   = obj.offsetLeft;
          objTop    = obj.offsetTop;
          objParent = obj.offsetParent;
          
          while( objParent.tagName.toUpperCase() != "BODY" )
          {
            objLeft  += objParent.offsetLeft;
            objTop   += objParent.offsetTop;
            objParent = objParent.offsetParent;
          }
      
          objHeight = obj.offsetHeight;
          objWidth = obj.offsetWidth;
      
          if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
          else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
          else if( overDiv.offsetTop >= ( objTop + objHeight ));
          else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
          else
          {
            obj.style.visibility = "hidden";
          }
        }
      }
    }
     
    /*
    * unhides <select> and <applet> objects (for IE only)
    */
    this.showElement = function ( elmID )
    {
      if( ie )
      {
        for( i = 0; i < document.all.tags( elmID ).length; i++ )
        {
          obj = document.all.tags( elmID )[i];
          
          if( !obj || !obj.offsetParent )
          {
            continue;
          }
        
          obj.style.visibility = "";
        }
      }
    }

	function  HolidayRec(d, m, y, desc)
	{
		this.d = d
		this.m = m
		this.y = y
		this.desc = desc
	}

	var HolidaysCounter = 0
	var Holidays = new Array()

	this.addHoliday = function  (d, m, y, desc)
	{
		Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
	}

	if (dom)
	{
		for	(i=0;i<imgsrc.length;i++)
		{
			img[i] = new Image
			img[i].src = imgDir + imgsrc[i]
		}
		document.write ("<div onclick='javascript:bShow=true' id='calendar'	style='z-index:+999;position:absolute;visibility:hidden;'><table	width="+((showWeekNumber==1)?250:220)+" style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:11px}' bgcolor='#ffffff'><tr bgcolor='#0000aa'><td><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:LMC_Class_Date.hideCalendar()'><IMG SRC='"+imgDir+"close.gif' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content'></span></td></tr>")
			
		if (showToday==1)
		{
			document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>")
		}
			
		document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>");
	}

	var	monthName =	new	Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月")
	var	monthName2 = new Array("1","2","3","4","5","6","7","8","9","10","11","12")
	if (startAt==0)
	{
		dayName = new Array	("日","一","二","三","四","五","六")
	}
	else
	{
		dayName = new Array	("一","二","三","四","五","六","日")
	}
	var	styleAnchor="text-decoration:none;color:black;"
	var	styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"

	this.swapImage = function (srcImg, destImg){
		if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
	}

	this.init = function ()	{
		if (!ns4)
		{
			if (!ie) { this.yearNow += 1900	}

			crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
			this.hideCalendar()

			crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth

			crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear

			monthConstructed=false;
			yearConstructed=false;

			if (showToday==1)
			{
				document.getElementById("lblToday").innerHTML =	todayString + " <a  onmousemove='javascript:window.status=\""+gotoString+"\"' onmouseout='javascript:window.status=\"\"' title='"+gotoString+"' style='"+styleAnchor+"' href='javascript:LMC_Class_Date.monthSelected=LMC_Class_Date.monthNow;LMC_Class_Date.yearSelected=LMC_Class_Date.yearNow;LMC_Class_Date.constructCalendar();'> 星期"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " +this.yearNow  + "年" + monthName2[this.monthNow].substring(0,3)	+ "月" + dateNow + "日</a>"
			}

			sHTML1="<span id='spanLeft'	style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='javascript:LMC_Class_Date.swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:LMC_Class_Date.decMonth()' onmouseout='javascript:clearInterval(LMC_Class_Date.intervalID1);LMC_Class_Date.swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onmousedown='javascript:clearTimeout(LMC_Class_Date.timeoutID1);LMC_Class_Date.timeoutID1=setTimeout(\"LMC_Class_Date.StartDecMonth()\",500)'	onmouseup='javascript:clearTimeout(LMC_Class_Date.timeoutID1);clearInterval(LMC_Class_Date.intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;"
			sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'	onmouseover='javascript:LMC_Class_Date.swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollRightMessage+"\"' onmouseout='javascript:clearInterval(LMC_Class_Date.intervalID1);LMC_Class_Date.swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='javascript:LMC_Class_Date.incMonth()' onmousedown='javascript:clearTimeout(LMC_Class_Date.timeoutID1);LMC_Class_Date.timeoutID1=setTimeout(\"LMC_Class_Date.StartIncMonth()\",500)'	onmouseup='javascript:clearTimeout(LMC_Class_Date.timeoutID1);clearInterval(LMC_Class_Date.intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif'	width=10 height=11 BORDER=0>&nbsp</span>&nbsp"
			sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'	onmouseover='javascript:LMC_Class_Date.swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectMonthMessage+"\"' onmouseout='javascript:LMC_Class_Date.swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='javascript:LMC_Class_Date.popUpMonth()'></span>&nbsp;"
			sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='javascript:LMC_Class_Date.swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectYearMessage+"\"'	onmouseout='javascript:LMC_Class_Date.swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"'	onclick='javascript:LMC_Class_Date.popUpYear()'></span>&nbsp;"
			
			document.getElementById("caption").innerHTML  =	sHTML1

			bPageLoaded=true
		}
	}

	this.hideCalendar = function ()	{
		crossobj.visibility="hidden"
		if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
		if (crossYearObj !=	null){crossYearObj.visibility="hidden"}

	    this.showElement( 'SELECT' );
		this.showElement( 'APPLET' );
	}

	this.padZero = function (num) {
		return (num	< 10)? '0' + num : num ;
	}

	this.constructDate = function (d,m,y)
	{
		sTmp = dateFormat
		sTmp = sTmp.replace	("dd","<e>")
		sTmp = sTmp.replace	("d","<d>")
		sTmp = sTmp.replace	("<e>",this.padZero(d))
		sTmp = sTmp.replace	("<d>",d)
		sTmp = sTmp.replace	("mmmm","<p>")
		sTmp = sTmp.replace	("mmm","<o>")
		sTmp = sTmp.replace	("mm","<n>")
		sTmp = sTmp.replace	("m","<m>")
		sTmp = sTmp.replace	("<m>",m+1)
		sTmp = sTmp.replace	("<n>",this.padZero(m+1))
		sTmp = sTmp.replace	("<o>",monthName[m])
		sTmp = sTmp.replace	("<p>",monthName2[m])
		sTmp = sTmp.replace	("yyyy",y)
		return sTmp.replace ("yy",this.padZero(y%100))
	}

	this.closeCalendar = function () {
		var	sTmp

		this.hideCalendar();
		ctlToPlaceValue.value =	this.constructDate(this.dateSelected,this.monthSelected,this.yearSelected);

		//ctlToPlaceValue.focus();
		//完成后取得该日期框的焦点
	}

	/*** Month Pulldown	***/

	this.StartDecMonth = function ()
	{
		this.intervalID1=setInterval("LMC_Class_Date.decMonth()",80)
	}

	this.StartIncMonth = function ()
	{
		this.intervalID1=setInterval("LMC_Class_Date.incMonth()",80)
	}

	this.incMonth = function  () {
		this.monthSelected++
		if (this.monthSelected>11) {
			this.monthSelected=0
			this.yearSelected++
		}
		this.constructCalendar()
	}

	this.decMonth = function  () {
		this.monthSelected--
		if (this.monthSelected<0) {
			this.monthSelected=11
			this.yearSelected--
		}
		this.constructCalendar()
	}

	this.constructMonth = function () {
		this.popDownYear()
		if (!monthConstructed) {
			sHTML =	""
			for	(i=0; i<12;	i++) {
				sName =	monthName[i];
				if (i==this.monthSelected){
					sName =	"<B>" +	sName +	"</B>"
				}
				sHTML += "<tr><td id='m" + i + "' onmouseover='javascript:this.style.backgroundColor=\"#FFCC99\"' onmouseout='javascript:this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='javascript:monthConstructed=false;LMC_Class_Date.monthSelected=" + i + ";LMC_Class_Date.constructCalendar();LMC_Class_Date.popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
			}

			document.getElementById("selectMonth").innerHTML = "<table width=70	style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='javascript:clearTimeout(LMC_Class_Date.timeoutID1)'	onmouseout='javascript:clearTimeout(LMC_Class_Date.timeoutID1);LMC_Class_Date.timeoutID1=setTimeout(\"LMC_Class_Date.popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>"

			monthConstructed=true
		}
	}

	this.popUpMonth = function () {
		this.constructMonth()
		crossMonthObj.visibility = (dom||ie)? "visible"	: "show"
		crossMonthObj.left = parseInt(crossobj.left) + 50
		crossMonthObj.top =	parseInt(crossobj.top) + 26

		this.hideElement( 'SELECT', document.getElementById("selectMonth") );
		this.hideElement( 'APPLET', document.getElementById("selectMonth") );			
	}

	this.popDownMonth = function ()	{
		crossMonthObj.visibility= "hidden"
	}

	/*** Year Pulldown ***/

	this.incYear = function () {
		for	(i=0; i<7; i++){
			newYear	= (i+nStartingYear)+1
			if (newYear==this.yearSelected)
			{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
			else
			{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
			document.getElementById("y"+i).innerHTML = txtYear
		}
		nStartingYear ++;
		bShow=true
	}

	this.decYear = function () {
		for	(i=0; i<7; i++){
			newYear	= (i+nStartingYear)-1
			if (newYear==this.yearSelected)
			{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
			else
			{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
			document.getElementById("y"+i).innerHTML = txtYear
		}
		nStartingYear --;
		bShow=true
	}

	this.selectYear = function (nYear) {
		this.yearSelected=parseInt(nYear+nStartingYear);
		yearConstructed=false;
		this.constructCalendar();
		this.popDownYear();
	}

	this.constructYear = function () {
		this.popDownMonth()
		sHTML =	""
		if (!yearConstructed) {

			sHTML =	"<tr><td align='center'	onmouseover='javascript:this.style.backgroundColor=\"#FFCC99\"' onmouseout='javascript:clearInterval(LMC_Class_Date.intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='javascript:clearInterval(LMC_Class_Date.intervalID1);LMC_Class_Date.intervalID1=setInterval(\"LMC_Class_Date.decYear()\",30)' onmouseup='javascript:clearInterval(LMC_Class_Date.intervalID1)'>-</td></tr>"

			j =	0
			nStartingYear =	this.yearSelected-3
			for	(i=(this.yearSelected-3); i<=(this.yearSelected+3); i++) {
				sName =	i;
				if (i==this.yearSelected){
					sName =	"<B>" +	sName +	"</B>"
				}

				sHTML += "<tr><td id='y" + j + "' onmouseover='javascript:this.style.backgroundColor=\"#FFCC99\"' onmouseout='javascript:this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='javascript:LMC_Class_Date.selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				j ++;
			}

			sHTML += "<tr><td align='center' onmouseover='javascript:this.style.backgroundColor=\"#FFCC99\"' onmouseout='javascript:clearInterval(LMC_Class_Date.intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='javascript:clearInterval(LMC_Class_Date.intervalID2);LMC_Class_Date.intervalID2=setInterval(\"LMC_Class_Date.incYear()\",30)'	onmouseup='javascript:clearInterval(LMC_Class_Date.intervalID2)'>+</td></tr>"

			document.getElementById("selectYear").innerHTML	= "<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;'	bgcolor='#FFFFDD' onmouseover='javascript:clearTimeout(LMC_Class_Date.timeoutID2)' onmouseout='javascript:clearTimeout(LMC_Class_Date.timeoutID2);LMC_Class_Date.timeoutID2=setTimeout(\"LMC_Class_Date.popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"

			yearConstructed	= true
		}
	}

	this.popDownYear = function () {
		clearInterval(this.intervalID1)
		clearTimeout(this.timeoutID1)
		clearInterval(this.intervalID2)
		clearTimeout(this.timeoutID2)
		crossYearObj.visibility= "hidden"
	}

	this.popUpYear = function () {
		var	leftOffset

		this.constructYear()
		crossYearObj.visibility	= (dom||ie)? "visible" : "show"
		leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
		if (ie)
		{
			leftOffset += 6
		}
		crossYearObj.left =	leftOffset
		crossYearObj.top = parseInt(crossobj.top) +	26
	}

	/*** calendar ***/
   this.WeekNbr = function (n) {
      // Algorithm used:
      // From Klaus Tondering's Calendar document (The Authority/Guru)
      // hhtp://www.tondering.dk/claus/calendar.html
      // a = (14-month) / 12
      // y = year + 4800 - a
      // m = month + 12a - 3
      // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
      // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
      // L = d4 / 1460
      // d1 = ((d4 - L) mod 365) + L
      // WeekNumber = d1 / 7 + 1
 
      year = n.getFullYear();
      month = n.getMonth() + 1;
      if (startAt == 0) {
         day = n.getDate() + 1;
      }
      else {
         day = n.getDate();
      }
 
      a = Math.floor((14-month) / 12);
      y = year + 4800 - a;
      m = month + 12 * a - 3;
      b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
      J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
      d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
      L = Math.floor(d4 / 1460);
      d1 = ((d4 - L) % 365) + L;
      week = Math.floor(d1/7) + 1;
 
      return week;
   }

	this.constructCalendar = function  () {
		var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

		var dateMessage
		var	startDate =	new	Date (this.yearSelected,this.monthSelected,1)
		var endDate

		if (this.monthSelected==1)
		{
			endDate	= new Date (this.yearSelected,this.monthSelected+1,1);
			endDate	= new Date (endDate	- (24*60*60*1000));
			numDaysInMonth = endDate.getDate()
		}
		else
		{
			numDaysInMonth = aNumDays[this.monthSelected];
		}

		datePointer	= 0
		dayPointer = startDate.getDay() - startAt
		
		if (dayPointer<0)
		{
			dayPointer = 6
		}

		sHTML =	"<table	 border=0 style='font-family:verdana;font-size:11px;'><tr>"

		if (showWeekNumber==1)
		{
			sHTML += "<td width=27 nowrap><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><!--img src='"+imgDir+"divider.gif' width=1--></td>"
		}

		for	(i=0; i<7; i++)	{
			sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
		}
		sHTML +="</tr><tr>"
		
		if (showWeekNumber==1)
		{
			sHTML += "<td align=right>" + this.WeekNbr(startDate) + "&nbsp;</td>"
		}

		for	( var i=1; i<=dayPointer;i++ )
		{
			sHTML += "<td>&nbsp;</td>"
		}
	
		for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
		{
			dayPointer++;
			sHTML += "<td align=right>"
			sStyle=styleAnchor
			if ((datePointer==odateSelected) &&	(this.monthSelected==omonthSelected)	&& (this.yearSelected==oyearSelected))
			{ sStyle+=styleLightBorder }

			sHint = ""
			for (k=0;k<HolidaysCounter;k++)
			{
				if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(this.monthSelected+1)))
				{
					if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==this.yearSelected)&&(parseInt(Holidays[k].y)!=0)))
					{
						sStyle+="background-color:#FFDDDD;"
						sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
					}
				}
			}

			var regexp= /\"/g
			sHint=sHint.replace(regexp,"&quot;")

			dateMessage = "onmousemove='javascript:window.status=\""+selectDateMessage.replace("[date]",this.constructDate(datePointer,this.monthSelected,this.yearSelected))+"\"' onmouseout='javascript:window.status=\"\"' "

			if ((datePointer==dateNow)&&(this.monthSelected==this.monthNow)&&(this.yearSelected==this.yearNow))
			{ sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:LMC_Class_Date.dateSelected="+datePointer+";LMC_Class_Date.closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font>&nbsp;</a></b>"}
			else if	(dayPointer % 7 == (startAt * -1)+1)
			{ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:LMC_Class_Date.dateSelected="+datePointer + ";LMC_Class_Date.closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" }
			else
			{ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:LMC_Class_Date.dateSelected="+datePointer + ";LMC_Class_Date.closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" }

			sHTML += ""
			if ((dayPointer+startAt) % 7 == startAt) { 
				sHTML += "</tr><tr>" 
				if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
				{
					sHTML += "<td align=right>" + (this.WeekNbr(new Date(this.yearSelected,this.monthSelected,datePointer+1))) + "&nbsp;</td>"
				}
			}
		}

		document.getElementById("content").innerHTML   = sHTML
		document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[this.monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
		document.getElementById("spanYear").innerHTML =	"&nbsp;" + this.yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
	}

	this.popUpCalendar = function (ctl,	ctl2, format) {
		var	leftpos=0
		var	toppos=0

		if (bPageLoaded)
		{
			if ( crossobj.visibility ==	"hidden" ) {
				ctlToPlaceValue	= ctl2
				dateFormat=format;

				formatChar = " "
				aFormat	= dateFormat.split(formatChar)
				if (aFormat.length<3)
				{
					formatChar = "/"
					aFormat	= dateFormat.split(formatChar)
					if (aFormat.length<3)
					{
						formatChar = "."
						aFormat	= dateFormat.split(formatChar)
						if (aFormat.length<3)
						{
							formatChar = "-"
							aFormat	= dateFormat.split(formatChar)
							if (aFormat.length<3)
							{
								// invalid date	format
								formatChar=""
							}
						}
					}
				}

				tokensChanged =	0
				if ( formatChar	!= "" )
				{
					// use user's date
					aData =	ctl2.value.split(formatChar)

					for	(i=0;i<3;i++)
					{
						if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
						{
							this.dateSelected = parseInt(aData[i], 10)
							tokensChanged ++
						}
						else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
						{
							this.monthSelected =	parseInt(aData[i], 10) - 1
							tokensChanged ++
						}
						else if	(aFormat[i]=="yyyy")
						{
							this.yearSelected = parseInt(aData[i], 10)
							tokensChanged ++
						}
						else if	(aFormat[i]=="mmm")
						{
							for	(j=0; j<12;	j++)
							{
								if (aData[i]==monthName[j])
								{
									this.monthSelected=j
									tokensChanged ++
								}
							}
						}
						else if	(aFormat[i]=="mmmm")
						{
							for	(j=0; j<12;	j++)
							{
								if (aData[i]==monthName2[j])
								{
									this.monthSelected=j
									tokensChanged ++
								}
							}
						}
					}
				}

				if ((tokensChanged!=3)||isNaN(this.dateSelected)||isNaN(this.monthSelected)||isNaN(this.yearSelected))
				{
					this.dateSelected = dateNow
					this.monthSelected =	this.monthNow
					this.yearSelected = this.yearNow
				}

				odateSelected=this.dateSelected
				omonthSelected=this.monthSelected
				oyearSelected=this.yearSelected

				aTag = ctl
				do {
					aTag = aTag.offsetParent;
					leftpos	+= aTag.offsetLeft;
					toppos += aTag.offsetTop;
				} while(aTag.tagName!="BODY");

				crossobj.left =	fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX
				crossobj.top = fixedY==-1 ?	ctl.offsetTop + toppos + ctl.offsetHeight +2 :	fixedY
//上面两句为窗口定位
				this.constructCalendar (1, this.monthSelected, this.yearSelected);
				crossobj.visibility=(dom||ie)? "visible" : "show"

				this.hideElement( 'SELECT', document.getElementById("calendar") );
				this.hideElement( 'APPLET', document.getElementById("calendar") );			

				bShow = true;
			}
			else
			{
				this.hideCalendar()
				if (ctlNow!=ctl) {this.popUpCalendar(ctl, ctl2, format)}
			}
			ctlNow = ctl
		}
	}

	document.onkeypress = function hidecal1 () { 
		if (event.keyCode==27) 
		{
			this.hideCalendar();
			
		}
	}
	document.onclick = function hidecal2 () { 		
		if (!bShow)
		{
		  	this.hideCalendar();
		}
		bShow = false
	}

	if(ie)
	{
		this.init();
	
	}
	else
	{
		window.onload=this.init
	}
//	written	by Tan Ling Wee
//	last updated 20 June 2003
//	email :	fuushikaden@yahoo.com

//////////////////////////////////////////////////////////////////////////////////
// Layers 
//////////////////////////////////////////////////////////////////////////////////

var layerQueue=new Array()
var layerIndex=-1


this.lw_createLayer = function  (layerName, top_pos, left_pos, width, height, bgcolor, bordercolor, z_index) {
	document.write("<div ONCLICK='javascript:event.cancelBubble=true' id='"+layerName+"' style='z-index:" + z_index + ";position:absolute;top:"+top_pos+";left:"+left_pos+";visibility:hidden;'><table bgcolor='"+bgcolor+"' style='border-width:1px;border-style:solid;border-color:" + bordercolor + "' cellpadding=2 cellspacing=0 width=0><tr><td valign=top width='"+width+"' height='"+height+"'><span id='"+layerName+"_content'></span></td></tr></table></div>")
}

this.lw_getObj = function  (objName) {
	return (dom)?document.getElementById(objName).style:ie?eval("document.all."+objName) :eval("document."+objName)
}

this.lw_showLayer = function  (layerName) {

	found=false
	for (i=0;i<=layerIndex;i++)
	{
		if (layerQueue[i]==layerName)
		{
			found=true
		}
	}

	if ((this.lw_getObj(layerName).visibility!="visible")&&(this.lw_getObj(layerName).visibility!="show"))
	{
		this.lw_getObj(layerName).visibility = (dom||ie)?"visible":"show"
		layerQueue[++layerIndex] = layerName

		this.hideElement( 'SELECT', document.getElementById(layerName) );
		this.hideElement( 'APPLET', document.getElementById(layerName) );
	}	
}

this.lw_hideLayer = function  () {
	this.showElement( 'SELECT', document.getElementById(layerQueue[layerIndex]) );
	this.showElement( 'APPLET', document.getElementById(layerQueue[layerIndex]) );

	this.lw_getObj(layerQueue[layerIndex--]).visibility = "hidden"
}

this.lw_hideLayerName = function  (layerName) {
	var i
	var tmpQueue=new Array()
	var newIndex=-1

	this.showElement( 'SELECT', document.getElementById(layerName) );
	this.showElement( 'APPLET', document.getElementById(layerName) );

	this.lw_getObj(layerName).visibility = "hidden"

	for (i=0;i<=layerIndex;i++)
	{
		if ((layerQueue[i]!="")&&(layerQueue[i]!=layerName))
		{
			tmpQueue [++newIndex] = layerQueue[i]			
			this.hideElement( 'SELECT', document.getElementById(layerQueue[i]) );
			this.hideElement( 'APPLET', document.getElementById(layerQueue[i]) );
		}
		
	}

	layerQueue = tmpQueue
	layerIndex = newIndex
}

this.lw_closeAllLayers = function () {
	while (layerIndex >= 0)
	{
		this.lw_hideLayer()
	}
}

this.lw_closeLastLayer = function () {
	if (layerIndex >= 0)
	{
		while ((this.lw_getObj(layerQueue[layerIndex]).visibility!="visible") && (layerIndex>0))
		{
			layerIndex--;
		}
		this.lw_hideLayer()
	}
}

this.lw_escLayer = function  (e) {
	if (navigator.appName=="Netscape")
	{
		var keyCode = e.keyCode?e.keyCode:e.which?e.which:e.charCode;
		if ((keyCode==27)||(keyCode==1))
		{
			this.lw_closeLastLayer()
		}
	}
	else
	if ((event.keyCode==0)||(event.keyCode==27))
	{
		this.lw_closeLastLayer()		
	}
}


var lw_leftpos = 0
var lw_toppos = 0
var lw_width = 0
var lw_height = 0

this.lw_calcpos = function (obj) {
	lw_leftpos=0
	lw_toppos=0
	lw_width = obj.offsetWidth
	lw_height = obj.offsetHeight

	var aTag = obj
	do {
		lw_leftpos += aTag.offsetLeft;
		lw_toppos += aTag.offsetTop;
		aTag = aTag.offsetParent;
	} while(aTag.tagName!="BODY");
}

document.onkeypress = this.lw_escLayer;
document.onclick = this.lw_closeAllLayers;
}